package com.xinjian.jianba.examples;

import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.BucketManager;
import com.qiniu.util.Auth;
import com.qiniu.common.Zone;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.model.FetchRet;

public class FetchDemo {

    public static void main(String args[]) {
        //设置需要操作的账号的AK和SK
    	String ACCESS_KEY = "tb1uBM7zB7VBopMs1-VHPnTwz0JsUYh9I194OMB6";
        String SECRET_KEY = "M-zy_OwUebkEmkbDxa6GPA2XMBVTDdHg3GtrkJx9";
        Auth auth = Auth.create(ACCESS_KEY, SECRET_KEY);

        Zone z = Zone.zone0();
        Configuration c = new Configuration(z);

        //实例化一个BucketManager对象
        BucketManager bucketManager = new BucketManager(auth, c);

        //文件保存的空间名和文件名
        String bucket = "jianjian";
        String key = "my-java.png";

        //要fetch的url
        String url = "http://images.jijile.vip/my-java.png";

        try {
            //调用fetch方法抓取文件
        	FetchRet ft= bucketManager.fetch(url, bucket, key);
        	System.out.println(ft.fsize);
        	System.out.println(ft.key);
        	System.out.println(ft.mimeType);
        	System.out.println(ft.toString());
        	
        	
        } catch (QiniuException e) {
            //捕获异常信息
            Response r = e.response;
            System.out.println(r.toString());
        }
    }

}
